package shuati.chuanzhibei;

import java.util.Scanner;

/**
 * @Date : 2022/11/26
 * @Description:
 */
public class p2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a,p,t;
         t = sc.nextInt();
        for (int i = 0; i < t; i++) {
            a=sc.nextInt();
            p= sc.nextInt();
            System.out.println(js(a, p));
        }

    }
    public static int js(int a,int p){
        if(p<16)
            a-=10;
        else if(p>20)
            a-=p-20;
        if(a<0) return 0;
        else return a;
    }
}
